package com.hulk.dryad.admin.controller.monitor;

import com.alibaba.druid.stat.DruidStatManagerFacade;
import com.hulk.dryad.common.component.R;
import com.hulk.dryad.manage.framework.tenant.TenantHierarchyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * SQL监控
 *
 * @author hulk
 */
@Api(value = "sql", tags = "SQL监控")
@RestController
@RequestMapping("/monitor/sql")
public class SqlMonitorController {

  @ApiOperation(value = "info", notes = "SQL监控详细信息")
  @GetMapping("/info")
  public R getInfo() {
      String tenantId = TenantHierarchyUtil.getTenantId();
	  DruidStatManagerFacade statManagerFacade = DruidStatManagerFacade.getInstance();
	  Object dataSource = statManagerFacade.getDruidDataSourceByName(tenantId);
	  List sm =  statManagerFacade.getSqlStatDataList(dataSource);
	  Collections.reverse(sm);
	  return R.ok(sm);
  }
}
